<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')" align-center :close-on-click-modal="false">
		<el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="110px" label-position="right" >
            <el-row :gutter="1">
                <el-col :span="12">
                    <el-form-item label="验证结果" prop="check_status">
                        <el-select v-model="form.check_status"  filterable style="width: 100%" placeholder="请选择" clearable>
                            <el-option v-for="item in checkList" :key="item.id" :label="item.name" :value="item.id"/>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="是否影响生产" prop="is_produce">
                        <el-select v-model="form.is_produce"  filterable style="width: 100%" placeholder="请选择" clearable>
                            <el-option v-for="item in produceList" :key="item.id" :label="item.name" :value="item.id"/>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-col>
                <el-form-item label="验证说明" prop="content">
                    <el-input v-model="form.content" type="textarea" clearable></el-input>
                </el-form-item>
            </el-col>
		</el-form>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增维修工单',
				edit: '维修验证',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			//表单数据
			form: {
				id: "",
				check_status: "",
                content:"",
                is_produce:"",
			},
			//验证规则
			rules: {
				// ware_name: [
				// 	{ required: true, message: '请输入维修工单名称' }
				// ],
				// ware_code: [
				// 	{ required: true, message: '请输入维修工单编号' }
				// ],
			},
            checkList:[
                {id:0,name:"未修复"},
                {id:1,name:"已修复"},
            ],//人员
            produceList:[
                {id:0,name:"否"},
                {id:1,name:"是"},
            ]
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//加载树数据
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = [];
					res = await this.$API.device.deviceTask.check.post(this.form);
					this.isSaveing = false;
					if (res.code == 1) {
						this.$emit('success', this.form, this.mode)
						this.visible = false;
						this.$message.success("验证成功")
					} else {
						this.$alert(res.message, "提示", { type: 'error' })
					}
				} else {
					return false;
				}
			})
		},
		//表单注入数据
		setData(data) {
			this.form.id = data.id
		},
	}
}
</script>

<style></style>
